package com.minyifang.wcspf.work.ui.home.activities;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
import android.widget.TextView;

import com.minyifang.wcspf.R;
import com.minyifang.wcspf.common.base.BaseActivity;
import com.minyifang.wcspf.common.base.BaseMvpActivity;
import com.minyifang.wcspf.common.utils.ToastHelper;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.Global;
import com.minyifang.wcspf.work.ui.home.model.TakeGoodsBean;
import com.minyifang.wcspf.work.ui.home.presenter.TakeGoodsPresenter;
import com.minyifang.wcspf.work.ui.home.view.TakeGoodsView;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import butterknife.BindView;

public class TakeGoodsActivity extends BaseMvpActivity<TakeGoodsView, TakeGoodsPresenter> implements TakeGoodsView {

    @BindView(R.id.tv_phoneNum)
    TextView tv_phoneNum;
    @BindView(R.id.iv_qrcode)
    ImageView iv_qrcode;

    private TakeGoodsBean bean;

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_take_goods;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        mPresenter.getGoodsInfo();
    }

    @Override
    protected TakeGoodsPresenter createPresenter() {
        return new TakeGoodsPresenter();
    }

    @Override
    public void getGoodsInfoRes(HttpRespond<TakeGoodsBean> respond) {
        if (respond.result == 1) {
            bean = respond.data;
            tv_phoneNum.setText(bean.getMobile());
            createQRCode(bean.getMobile());

        } else if (respond.result == -1) {
            Global.reLogin(this);
        } else
            ToastHelper.getInstance(this).showWarn(respond.message);
    }

    private void createQRCode(String mobile) {

        Bitmap bitmap = CodeUtils.createImage(mobile, 400, 400, BitmapFactory.decodeResource(getResources(), R.mipmap.img_place_holder));
        iv_qrcode.setImageBitmap(bitmap);
    }

    @Override
    public void showLoadingView() {

    }

    @Override
    public void hideLoadingView() {

    }

    @Override
    public void onNetworkError() {

    }


}
